package com.itheima.test1;

public class Test1MaoPao {
    public static void main(String[] args) {
        int[] arr = {5,3,4,1,2};
        //1 2 3 4 5
        //第一轮
        //把最大值找出来,放在最右边
        //-1是为了索引不超出范围
        for (int i = 0; i < arr.length -1; i++) {
            if(arr[i]>arr[i+1]){
                //元素调换
                int temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
            }
        }
        printArr(arr);

        //第二轮:
        for (int i = 0; i < arr.length -1 -1; i++) {
            if(arr[i]>arr[i+1]){
                //元素调换
                int temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
            }
        }
        printArr(arr);

        //第三轮:
        for (int i = 0; i < arr.length -1 -2; i++) {
            if(arr[i]>arr[i+1]){
                //元素调换
                int temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
            }
        }
        printArr(arr);

        //第四轮:
        for (int i = 0; i < arr.length -1 -3; i++) {
            if(arr[i]>arr[i+1]){
                //元素调换
                int temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp;
            }
        }
        printArr(arr);



    }

    private static void printArr(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();

    }
}
